Skip to content

关闭注册表键 - RegistryCloseKey

函数简介

关闭注册表键句柄,释放系统资源。

接口名称

RegistryCloseKey

DLL调用

cpp
int32_t RegistryCloseKey(int64_t instance, int64_t key);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
key长整数型注册表键句柄,由 RegistryOpenKeyRegistryCreateKey 返回

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// rootKey=1 表示 HKEY_CURRENT_USER
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
    std::string version = ola.RegistryGetString(key, "Version");
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long key = ola.RegistryOpenKey(1, @"Software\OLAPlug");
if (key != 0)
{
    string version = ola.RegistryGetString(key, "Version");
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
key = ola.RegistryOpenKey(1, r"Software\OLAPlug")
if key != 0:
    version = ola.RegistryGetString(key, "Version")
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
    String version = ola.RegistryGetString(key, "Version");
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
cpp
var ola = com("OlaPlug.OlaSoft")
var key = ola.RegistryOpenKey(1, "Software\\OLAPlug")
if(key) {
    var version = ola.RegistryGetString(key, "Version")
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
key = ola.RegistryOpenKey(1, "Software\OLAPlug")
If key <> 0 Then
    version = ola.RegistryGetString(key, "Version")
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
text
.局部变量 ola, OLAPlug
ola.创建 ()
key = ola.RegistryOpenKey (1, “Software\\OLAPlug“)
.如果真 (key ≠ 0)
    version = ola.RegistryGetString (key, "Version")
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if(key){
    var version = ola.RegistryGetString(key, "Version");
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 key = ola.RegistryOpenKey(1, "Software\\OLAPlug")
如果真 (key ≠ 0)
{
    文本型 version = ola.RegistryGetString(key, "Version")
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
    std::string version = ola.RegistryGetString(key, "Version");
    ola.RegistryCloseKey(key); // 必须关闭,否则句柄泄漏
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long key = RegistryOpenKey(instance, 1, "Software\\OLAPlug");
if (key != 0) {
    RegistryCloseKey(instance, key);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long key = RegistryOpenKey(instance, 1, @"Software\OLAPlug");
if (key != 0)
{
    RegistryCloseKey(instance, key);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
key = ola.RegistryOpenKey(instance, 1, b"Software\\OLAPlug")
if key:
    RegistryCloseKey(instance, key);
}

返回值

整数型。1 成功,0 失败。

注意事项

  • 关闭后句柄失效,不可再使用。
  • 每个打开的注册表键都必须调用此函数关闭,避免资源泄漏。
  • 重复关闭同一个句柄可能导致失败。